package com.foreknow.service.impl;

import com.foreknow.dao.impl.AdminDaoImpl;
import com.foreknow.db.DBManager;
import com.foreknow.model.Admin;
import com.foreknow.service.AdminService;

import java.sql.Connection;
import java.sql.SQLException;

public class AdminServiceImpl implements AdminService {
private AdminDaoImpl adminDao = new AdminDaoImpl();
    @Override
    public Admin getAdminByNameByPass(String adminName, String password) {
        DBManager db = DBManager.getInstance();
        Connection conn = db.getConnection();
        adminDao.setConnection(conn);
        Admin admin = null;
        admin = adminDao.getAdminByNameByPass(adminName, password);
        return admin;
    }

    @Override
    public boolean register(Admin admin) {
        DBManager db = DBManager.getInstance();
        Connection conn = db.getConnection();
        adminDao.setConnection(conn);
        boolean isRight = adminDao.register(admin);
        try {
            conn.commit();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return isRight;
    }
}
